import { staffContractListUrl } from '../../../../api/individual'
import { post } from '../../../../utils/index'

Page({
  data: {
    params: { page: 1, pageSize: 10 },
    finished: false,
    list: [],
    bgList: ['blue-color-bg', 'yellow-color-bg', 'green-color-bg', 'pink-color-bg', 'purple-color-bg']
  },
  async loadData () { // 获取合同列表
    let { params, finished } = this.data
    if (finished) {
      return
    }
    let { data: { rows, total } } = await post(staffContractListUrl, params, {}, false)
    let { list } = this.data
    list = list.concat(rows)
    params.page++
    if (list.length >= total) {
      finished = true
    }
    this.setData({ params, finished, list })
  },
  onPullDownRefresh () { // 上拉刷新
    const { params } = this.data
    params.page = 1
    this.setData({ params, finished: false, list: [] })
    this.loadData()
  },
  onReachBottom () { // 下拉加载更多
    this.loadData()
  },
  onShow () {
    this.loadData()
  }
})